/*******************************************************************************
Replication Materials for Blau, Kahn, Brummund, Cook, and Larson-Koester "Is 
There Still Son Preference in the United States?"

Table AT2

Date Modified: 10/19/2019

*******************************************************************************/




*-------------------------------------------------------------------------------
                                   *LOAD DATA
*-------------------------------------------------------------------------------
use "$acs\acs_data",clear


*-------------------------------------------------------------------------------
                                 *RESTRICT SAMPLE
*-------------------------------------------------------------------------------
keep if nonrkids == 0 & nonusbirth == 0 & sfrelate == 0 & father_sample != 1 ///
	& multi_sample != 1 & mult == 0 & female == 1 & oldc <=12 & ///
	inrange(age,18,40)==1 & foster_hh == 0 & nchild18>=1
drop if citizen==1
drop if marst == 5


*-------------------------------------------------------------------------------
                                 *CREATE VARS
*-------------------------------------------------------------------------------
* indicator for boy
forv jj = 1/4 {
	g c_male`jj' = (c_female`jj' == 0)
}

*-------------------------------------------------------------------------------
                              *SET UP PUT EXCEL FILE
*-------------------------------------------------------------------------------
putexcel set "$toutput\TA_2", replace
putexcel A1 = "Table A2: Boy/Girl Ratio, First Child" 
putexcel B2 = "Natives"
putexcel C2 = "Immigrants"
putexcel A2 = "A. All Married Women"
putexcel A3 = "Ratio"
putexcel A4 = "95% Confidence Interval"
putexcel A5 = "Sample Size"
putexcel A7 = "B. Married Women in First Marriage"
putexcel A8 = "Ratio"
putexcel A9 = "95% Confidence Interval"
putexcel A10 = "Sample Size"
putexcel A12 = "C. All Women"
putexcel A13 = "Ratio"
putexcel A14 = "95% Confidence Interval"
putexcel A15 = "Sample Size"


*-------------------------------------------------------------------------------
                     *CALCULATE SUMMARY STATS FOR DIFFERENT SAMPLES
*-------------------------------------------------------------------------------
*specify weights
global gweight "hhwtnorm"

*NATIVES, ALL MARRIED WOMEN
sum c_male1  [aw = $gweight] if native == 1 & (marst == 1)
cii means r(N) r(mean) r(sd) // r(lb) r(ub), x/(1-x)

	// variables:
	local ratio = round(r(mean)/(1-r(mean)), 0.0001)
	local left = round(r(lb)/(1-r(lb)), 0.0001)
	local right = round(r(ub)/(1-r(ub)), 0.0001)
	*local ci = [`left', `right']
	local ss = r(N)
	
	// put into excel:
	putexcel B3 = "`ratio'"
	putexcel B4 = "[`left', `right']"
	putexcel B5 = "`ss'"
	
*NATIVES, MARRIED WOMEN IN 1ST MARRIAGE
sum c_male1  [aw = $gweight] if native == 1 &  (marst == 1 | marst == 2) & bothfirmarr == 1
cii means r(N) r(mean) r(sd)

	// variables:
	local ratio = round(r(mean)/(1-r(mean)), 0.0001)
	local left = round(r(lb)/(1-r(lb)), 0.0001)
	local right = round(r(ub)/(1-r(ub)), 0.0001)
	*local ci = [`left', `right']
	local ss = r(N)
	
	// put into excel:
	putexcel B8 = "`ratio'"
	putexcel B9 = "[`left', `right']"
	putexcel B10 = "`ss'"

*NATIVES, ALL WOMEN
sum c_male1  [aw = $gweight] if native == 1 
cii means r(N) r(mean) r(sd)

	// variables:
	local ratio = round(r(mean)/(1-r(mean)), 0.0001)
	local left = round(r(lb)/(1-r(lb)), 0.0001)
	local right = round(r(ub)/(1-r(ub)), 0.0001)
	*local ci = [`left', `right']
	local ss = r(N)
	
	// put into excel:
	putexcel B13 = "`ratio'"
	putexcel B14 = "[`left', `right']"
	putexcel B15 = "`ss'"

*IMMIGRANTS, ALL MARRIED WOMEN
sum c_male1  [aw = $gweight] if native == 0 & (marst == 1)
cii means r(N) r(mean) r(sd)

	// variables:
	local ratio = round(r(mean)/(1-r(mean)), 0.0001)
	local left = round(r(lb)/(1-r(lb)), 0.0001)
	local right = round(r(ub)/(1-r(ub)), 0.0001)
	*local ci = [`left', `right']
	local ss = r(N)
	
	// put into excel:
	putexcel C3 = "`ratio'"
	putexcel C4 = "[`left', `right']"
	putexcel C5 = "`ss'"

*IMMIGRANTS, MARRIED WOMEN IN 1ST MARRIAGE
sum c_male1  [aw = $gweight] if native == 0  & (marst == 1 | marst == 2) & bothfirmarr == 1
cii means r(N) r(mean) r(sd)

	// variables:
	local ratio = round(r(mean)/(1-r(mean)), 0.0001)
	local left = round(r(lb)/(1-r(lb)), 0.0001)
	local right = round(r(ub)/(1-r(ub)), 0.0001)
	*local ci = [`left', `right']
	local ss = r(N)
	
	// put into excel:
	putexcel C8 = "`ratio'"
	putexcel C9 = "[`left', `right']"
	putexcel C10 = "`ss'"


*IMMIGRANTS, ALL WOMEN
sum c_male1  [aw = $gweight] if native == 0 
cii means r(N) r(mean) r(sd)

	// variables:
	local ratio = round(r(mean)/(1-r(mean)), 0.0001)
	local left = round(r(lb)/(1-r(lb)), 0.0001)
	local right = round(r(ub)/(1-r(ub)), 0.0001)
	*local ci = [`left', `right']
	local ss = r(N)
	
	// put into excel:
	putexcel C13 = "`ratio'"
	putexcel C14 = "[`left', `right']"
	putexcel C15 = "`ss'"

